package com.example.demo2.service;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo2.entity.Customer;
import com.example.demo2.entity.DTO.ShopPlaceDTO;
import com.example.demo2.entity.ShopPlace;
import com.example.demo2.mapper.ShopPlaceMapper;
import org.apache.logging.log4j.util.Strings;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Date;

@Service
public class ShopPlaceService extends ServiceImpl<ShopPlaceMapper, ShopPlace> {

    //根据省code 分页查询所有商品
    public IPage<ShopPlace> findPageByCode(ShopPlaceDTO shopPlaceDTO) {
        LambdaQueryWrapper<ShopPlace> lqw = new LambdaQueryWrapper<>();
        lqw.eq(shopPlaceDTO.getProvinceCode() != null, ShopPlace::getProvinceCode, shopPlaceDTO.getProvinceCode());
        lqw.eq(shopPlaceDTO.getCityCode() != null, ShopPlace::getCityCode, shopPlaceDTO.getCityCode());
        lqw.eq(shopPlaceDTO.getCountyCode() != null, ShopPlace::getCountyCode, shopPlaceDTO.getCountyCode());
        lqw.like(shopPlaceDTO.getName() != null, ShopPlace::getName,shopPlaceDTO.getName());
        Page<ShopPlace> iPage = new Page<>(shopPlaceDTO.getPage(), shopPlaceDTO.getLimit());
        return page(iPage, lqw);
    }

    public Boolean addShop(ShopPlace shopPlace) {
        shopPlace.setCreateTime(DateUtil.toLocalDateTime(new Date()));
        shopPlace.setUpdateTime(DateUtil.toLocalDateTime(new Date()));
        boolean save = save(shopPlace);
        return save;
    }

    public Boolean updateShop(ShopPlace shopPlace) {
        shopPlace.setUpdateTime(DateUtil.toLocalDateTime(new Date()));
        boolean b = updateById(shopPlace);
        return b ;
    }

    public Boolean deleteShop(Integer id) {
        boolean b = removeById(id);
        return b;
    }
//
//    //根据市code 分页查询所有商品
//    public IPage<ShopPlace> findPageByCity(ShopPlaceDTO shopPlaceDTO) {
//        LambdaQueryWrapper<ShopPlace> lqw = new LambdaQueryWrapper<>();
//        lqw.eq(ShopPlace::getProvinceCode, shopPlaceDTO.getProvinceCode());
//        lqw.eq(ShopPlace::getCityCode, shopPlaceDTO.getCityCode());
//        Page<ShopPlace> iPage = new Page<>(shopPlaceDTO.getPage(), shopPlaceDTO.getLimit());
//        return page(iPage, lqw);
//    }
//
//    //根据区code 分页查询所有商品
//    public IPage<ShopPlace> findPageByCounty(ShopPlaceDTO shopPlaceDTO) {
//        LambdaQueryWrapper<ShopPlace> lqw = new LambdaQueryWrapper<>();
//        lqw.eq(ShopPlace::getProvinceCode, shopPlaceDTO.getProvinceCode());
//        lqw.eq(ShopPlace::getCityCode, shopPlaceDTO.getCityCode());
//        lqw.eq(ShopPlace::getCountyCode, shopPlaceDTO.getCountyCode());
//        Page<ShopPlace> iPage = new Page<>(shopPlaceDTO.getPage(), shopPlaceDTO.getLimit());
//        return page(iPage, lqw);
//    }

}
